﻿namespace XGameLibrary.Controls
{
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Input;

    using XGameLibrary.Input;

    public class LinkLabel : Control
    {
        private Color selectedColor;

        public LinkLabel()
        {
            this.TabStop = true;
            this.Position = Vector2.Zero;

            this.SelectedColor = Color.Red;
        }

        public Color SelectedColor
        {
            get
            {
                return this.selectedColor;
            }

            set
            {
                this.selectedColor = value;
            }
        }

        public override void Update(GameTime gameTime)
        {
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.DrawString(
                this.SpriteFont,
                this.Text,
                this.Position,
                this.HasFocus ? this.SelectedColor : this.Color);
        }

        public override void HandleInput()
        {
            if (!this.HasFocus)
            {
                return;
            }

            if (InputHandler.KeyReleased(Keys.Enter))
            {
                this.OnSelected(null);
                Control.Press.Play();
            }
        }
    }
}
